home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
WINDOWS
/
MDIT.ARJ
/
MDIT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-03-31
|
6KB
|
189 lines
/****************************************************************************
Module name: MDIT.C
Programmer : Jeffrey M. Richter & Elvira Peretsman.
Modified : V. M. Vanderburg & M.T. Peterson, TriTechnologies
- Converted to multithreading
- Removed original comments
ATTRIBUTIONS:
With the exception of the PCthread calls, this code was taken directly
from the source disk furnished with the Windows Developer's Guide,
M&T Press, by Jeffrey M. Richter. I highly recommend Mr. Richter's
book both for its readability and the structure and quality of the
code.
*****************************************************************************/
/*
#include "..\nowindws.h"
#undef NOCTLMGR
#undef NOGDI
#undef NOKERNEL
#undef NOMB
#undef NOMDI
#undef NOMENUS
#undef NOMSG
#undef NOSYSMETRICS
#undef NOUSER
#undef NOWINMESSAGES
#undef NOWINSTYLES
*/
#include <windows.h>
#include "mdit.h" /* includes pcthread.h */
char g_szAppName[] = "PCthreads(tm) for Windows";
HANDLE g_hInstance = NULL;
HANDLE g_hAccelTable = NULL;
HWND g_hWndMDITClient = NULL;
pcthread_attr_t g_th_attr;
/************************* Main Application Loop ****************************/
int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow) {
MSG msg;
HWND hWndFrame;
if (hPrevInstance != NULL)
{
MessageBox(NULL, "MDIT application is already running.", g_szAppName,
MB_OK | MB_ICONINFORMATION);
return(0);
}
/*
* -- These next two calls create and initialize a handle to
* a thread attributes object. When this attributes object
* is passed to the pcthread_create() routine (see thread.c),
* it will cause the pcthread kernel to create a thread with
* a stack size of 512 words, or 1024 bytes.
*/
pcthread_attr_create(&g_th_attr);
pcthread_attr_setstacksize(&g_th_attr, 512 );
g_hInstance = hInstance;
if (!RegisterFrameWndClass())
return(0);
if (!RegisterThreadWndClass())
return(0);
hWndFrame = CreateWindow("Frame", g_szAppName,
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_MAXIMIZE | WS_VISIBLE |
WS_MAXIMIZEBOX | WS_MINIMIZEBOX,
CW_USEDEFAULT, nCmdShow, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, g_hInstance, NULL);
if (hWndFrame == NULL)
return(0);
/*
* -- Multithreaded Windows applications are characterized
* by heavy usage of the PeekMessage() service rather than
* the GetMessage() service. This is because the GetMessage()
* service blocks all threads until a message is available.
*
* Note also the presence of the ubiguitous pcthread_yield()
* function. This allows other threads to run (but does not
* allow other window apps to run, i.e., it does for threads
* what Yield() does for other Win Apps).
*/
for (;;)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (!TranslateMDISysAccel(g_hWndMDITClient, &msg))
{
if (g_hAccelTable == NULL || !TranslateAccelerator(hWndFrame, g_hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
if (msg.message == WM_QUIT)
{
break;
}
pcthread_yield();
}
return(msg.wParam);
}
HWND FAR PASCAL CreateMDITChild (LPSTR szClassName, LPSTR szWindowName,
DWORD dwStyle, short x, short y, short nWidth, short nHeight,
HWND hWndMDITClient, HANDLE hInstance, LONG lParam)
{
MDICREATESTRUCT cs;
HWND hWndChild;
th_list_p_t th_p;
cs.szClass = szClassName;
cs.szTitle = szWindowName;
cs.hOwner = hInstance;
cs.x = x;
cs.y = y;
cs.cx = nWidth;
cs.cy = nHeight;
cs.style = dwStyle;
cs.lParam = lParam;
hWndChild = (HWND) SendMessage(hWndMDITClient, WM_MDICREATE,
0, (LONG) (LPMDICREATESTRUCT) &cs);
return(hWndChild);
}
void FAR PASCAL ChangeMDITMenu (HWND hWndFrame, HWND hWndClient,
HMENU hMenuNew, WORD wMenuID)
{
WORD wCount;
HMENU hSubMenu = 0;
wCount = GetMenuItemCount(hMenuNew);
while (wCount)
{
hSubMenu = GetSubMenu(hMenuNew, wCount - 1);
if ((int) GetMenuState(hSubMenu, wMenuID, MF_BYCOMMAND) != -1)
break;
wCount--;
}
SendMessage(hWndClient, WM_MDISETMENU, 0, MAKELONG(hMenuNew, hSubMenu));
DrawMenuBar(hWndFrame);
}
BOOL FAR PASCAL AboutProc (HWND hDlg, WORD wMsg, WORD wParam, LONG lParam)
{
char szBuffer[100];
BOOL fProcessed = TRUE;
switch (wMsg)
{
case WM_INITDIALOG:
wsprintf(szBuffer, "%s at %s", (LPSTR) __DATE__, (LPSTR) __TIME__);
SetWindowText(GetDlgItem(hDlg, ID_VERSION), szBuffer);
break;
case WM_COMMAND:
switch (wParam)
{
case IDOK: case IDCANCEL:
if (HIWORD(lParam) == BN_CLICKED)
EndDialog(hDlg, wParam);
break;
default:
break;
}
break;
default:
fProcessed = FALSE; break;
}
return(fProcessed);
}